#include "sbridge.h"
#include "../bulk_storage/bulk_storage.h"

#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>

int main()
{
  char line[80];
  struct sbridge * sb;
  struct store * sbstore = store_open_cached("sb_store", "sb_store.fat",
					     sizeof(struct sbridge), (off_t)100, (off_t)2000);
  int i;
  
  for (i = 0; i < 4; i++)
      fgets(line, 82, stdin); //In *.sal file, the data just begin from line 10; 

  while((fgets(line, 82, stdin) !=NULL) && (strncmp("SCRIPT>>>> nolog", line, 16))) {
    
    i = store_new (sbstore);
    
    sb = store_read(sbstore, i);
    
    strncpy(sb->aa1name, &(line[9]), 3);

    sb->aa1chain = line[22];
    
    strncpy(sb->aa1atom, &(line[27]), 3);

    strncpy(sb->aa2name, &(line[38]), 3);
    
    sb->aa2chain = line[51];

    strncpy(sb->aa2atom, &(line[56]), 3);

    line[19] = '\0';
    sb->aa1number = atoi(&(line[16]));
    
    line[48] = '\0';
    sb->aa2number = atoi(&(line[45]));

	
    sb->distance = atof(&(line[62]));

    //printf("name1= %c%c%c, num1= %d, chain1= %c, atom1= %c%c%c, name2= %c%c%c, num2= %d, chain2= %c, atom2= %c%c%c, dist= %f\n",sb->aa1name[0], sb->aa1name[1], sb->aa1name[2], sb->aa1number, sb->aa1chain,sb->aa1atom[0], sb->aa1atom[1],sb->aa1atom[2], sb->aa2name[0],sb->aa2name[1],sb->aa2name[2], sb->aa2number, sb->aa2chain, sb->aa2atom[0], sb->aa2atom[1],sb->aa2atom[2], sb->distance);
  
    store_write(sbstore, i);
  
    store_release(sbstore, i);
  }
  
  store_close(sbstore);
  return 0;
}

    
    
